#include "AppDelegate.h"
#include "cocos2d.h"
#include "GameLayer.h"
#include "LoginLayer.h"
#include "PlayerListLayer.h"
#include <tcPhysics/tc_physics.h>
#include <tcLogic/tc_logic.h>
#include <tcSound/tc_sound.h>
#include <tcDatabase/tc_chessboard.h>

using namespace cocos2d;

AppDelegate::AppDelegate()
{
	tc_database_init();
	tc_physics_init();
	tc_sound_init();
	tc_logic_init();
}

AppDelegate::~AppDelegate()
{
	tc_logic_exit();
	tc_sound_exit();
	tc_physics_exit();
	tc_database_exit();
}

bool AppDelegate::initInstance()
{
    CCEGLView* pMainWnd = new CCEGLView();
    pMainWnd->Create(TEXT("Tanchess"), TC_SCREEN_HEIGHT, TC_SCREEN_WIDTH);
    return true;
}

bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView());

    // sets landscape mode
    pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);

    // turn on display FPS
    pDirector->setDisplayFPS(false);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(TC_FPS);

    // create a scene. it's an autorelease object
    CCScene *pScene = GameLayer::scene();
	//CCScene *pScene = LoginLayer::scene();
	//CCScene *pScene = PlayerListLayer::scene();
	
    pDirector->runWithScene(pScene);
    return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
    CCDirector::sharedDirector()->pause();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
    CCDirector::sharedDirector()->resume();
}
